#include "BlockQueue.hpp"

void *Producer(void *arg)
{
    BlockQueue<int> *bq = static_cast<BlockQueue<int> *>(arg);
    int data = 1;
    while (true)
    {
        bq->Equeue(data++);
        std::cout << "生产了一个数据 : " << data << std::endl;
    }
}

void *Consumer(void *arg)
{
    BlockQueue<int> *bq = static_cast<BlockQueue<int> *>(arg);
    while (true)
    {
        
        int data = bq->Pop();
        std::cout <<"消费了一个数据 : " << data << std::endl;
        
    }
}

int main()
{
    BlockQueue<int> bq;
    pthread_t c[2], p[3];
    pthread_create(c, nullptr, Consumer, (void *)&bq);
    pthread_create(c+1, nullptr, Consumer, (void *)&bq);

    pthread_create(p, nullptr, Producer, (void *)&bq);
    pthread_create(p+1, nullptr, Producer, (void *)&bq);
    pthread_create(p+2, nullptr, Producer, (void *)&bq);

    pthread_join(c[0], nullptr);
    pthread_join(c[1], nullptr);
    pthread_join(p[0], nullptr);
    pthread_join(p[1], nullptr);
    pthread_join(p[2], nullptr);

    return 0;
}